
import parole
from parole.colornames import colors
from parole.display import interpolateRGB
import pygame, random

import sim, main, sim_items
from util import *

class Potion(sim_items.Potion):
    def __init__(self):
        sim_items.Potion.__init__(self, "mistform", "!",
                ('go', 'life'),
                idDescription="Get ready for a wild ride.")
        self.killText = 'Resolidifying here kills you instantly!'

    def quaff(self, quaffer):
        if not quaffer.corporeal:
            if visible(quaffer):
                main.transient('Nothing seems to happen.', quaffer.parentTile)
            return

        self.duration = 30000 + random.randint(0, 30)*1000
        main.schedule(sim.Event('mistform warning',
            main.schedule.time+self.duration-10000, args=(self, quaffer),
            dests=[self]))
        main.schedule(sim.Event('mistform warning',
            main.schedule.time+self.duration-5000, args=(self, quaffer),
            dests=[self]))
        main.schedule(sim.Event('mistform warning',
            main.schedule.time+self.duration-2000, args=(self, quaffer),
            dests=[self]))

        quaffer.corporeal = not quaffer.corporeal
        self.origBloodClass = quaffer.bloodClass
        quaffer.bloodClass = None
        quaffer.identify(self)
        main.schedule(sim.Event('statusNote+', main.schedule.time, (quaffer,
            'mist'), dests=[quaffer]))
        main.schedule(sim.Event('statusNote-', main.schedule.time +\
            self.duration, (quaffer, 'mist'), dests=[quaffer, self]))
        if quaffer is main.player:
            main.transient('Your body and possessions undergo a painful '
                        'and wretched transformation. You dissolve into a '
                        'hovering cloud of living mist!')
        elif visible(quaffer):
            main.transient('%s dissolves into a hovering cloud of living mist!'\
                    % quaffer.noun(definite=1, capitalized=1),
                    quaffer.parentTile)
        self.quaffer = quaffer

    def listen(self, event):
        sim_items.Potion.listen(self, event)

        if event.id == 'statusNote-':
            creature, status = event.args
            if creature is self.quaffer and status == 'mist':
                self.quaffer.corporeal = not self.quaffer.corporeal
                self.quaffer.bloodClass = self.origBloodClass
                if self.quaffer is main.player:
                    main.transient('Your body and possessions undergo a painful '
                                'and wretched transformation. You return to a '
                                'solid existence.')
                elif visible(self.quaffer):
                    main.transient('%s resolidifies!'\
                            % self.quaffer.noun(definite=1, capitalized=1),
                            self.quaffer.parentTile)

                # see if the creature dies
                if creature.corporeal and creature.blockedAt(creature.parentTile):
                    if creature is main.player:
                        main.transient('Resolidifying here kills you '\
                                'instantly!')
                    elif visible(creature):
                        main.transient('Resolidifying here kills %s '\
                                'instantly!' % creature.noun(definite=1))
                    main.schedule(sim.Event('set stat', main.schedule.time,
                        (creature, 'hp', 0), dests=[creature]))
                    creature.lastDamageSource = self
                    

        elif event.id == 'mistform warning':
            potion, quaffer = event.args
            if potion is self and quaffer is main.player:
                main.transient('You feel that you could resolidify at any '
                        'instant!')

#========================================
thingClass = Potion






